class CreateTriggers < ActiveRecord::Migration
  def self.up
    config = ActiveRecord::Base.connection.instance_variable_get("@config")
    if config[:adapter] == "mysql"
      mysql_file = "#{RAILS_ROOT}/script/mysql/triggers.sql"
      %x[mysql -u#{config[:username]} -p"#{config[:password]}" -h #{config[:host]} #{config[:database]} < '#{mysql_file}']
    end
  end

  def self.down
    adapter = ActiveRecord::Base.connection.instance_variable_get("@config")[:adapter]
    %w(check_in_or_out check_hour_bank).each do |t|
      execute "DROP TRIGGER IF EXISTS #{t}"
    end if adapter == "mysql"
  end
end
